#ifndef __TREE_
#define __TREE_

#include "define.h"
#include "ulib.h"


class CNode {
public:
	int id;
	CUString label;
	int parent;
	int child[NUM_MAX_CHILD];
	int num_child;
	int span_from;
	int span_to;
	int level;
	int num_cross;
	int tok_aligns_tgt[NUM_MAX_ALIGN];
	int num_tok_aligns;

public:
	CNode()	{
		Init();
	}
	void Init()	{
		id = NULL_NUM;
		label = NULL_STR;
		parent = NULL_NUM;
		num_child = 0;
		span_from = NULL_NUM;
		span_to = NULL_NUM;
		level = NULL_NUM;
		num_cross = 0;
		num_tok_aligns=0;
	}

	bool IsTerminal()	{
		if( num_child == 0 )	{
			return true;
		}
		else	return false;
	}

	void AddAlign( int tgt )	{
		// skip if exist
		for( int i=0; i<num_tok_aligns; i++ )	{
			if( tok_aligns_tgt[i] == tgt )	{
				return;
			}
		}

		tok_aligns_tgt[num_tok_aligns] = tgt;
		num_tok_aligns++;
	}


};

class CTree {
public:
	CTree();
	~CTree();

	bool Init();
	bool LoadTree( CUString str );
	void Print();
	void PrintParse2File( CUTextFile &file ); 
	void PrintLex2File( CUTextFile &file ); 
	void PrintLexPos2File( CUTextFile &file ); 
	void PrintReordInfo2File( CUTextFile &file ); 
	void PrintStrRecurr( int curr_idx, CUString &ures);
	void GetTraverseList( int ls[], int &s, int start_id );
	void GetLexNodeList( int ls[], int &s, int start_id );
	int Lex2Node( int lex_id );
	CNode *GetNodeByLexID( int lex_id );
	void UpdateSpan();
	void UpdateTgtAlign();
	void UpdateCross();
	void ClearCross();
	bool SetSpan();
	void ReorderWA();
	CNode* GetNodeByID( int id );
	void Dump( FILE *fp );

	CNode node[NUM_MAX_NODE];
	int num_node;

};

#endif

